import Taro, { Component } from '@tarojs/taro'
import { AtTabs, AtInput, AtButton, AtTabsPane,AtListItem ,AtList } from 'taro-ui'
import { View, ScrollView } from '@tarojs/components'
import { DNavBar, DAtInpute, DFinancingRecord, DItemError } from '@/components'
import '../financingrecord/financingrecord.scss'
import '../freezingdetails/freezingdetails.scss'
import './cardealer.scss'
import '../drawback/drawback.scss'
import http from '@/api'
const entLogo = require('./entLogo.png')
export default class FinancingrecordBox extends Component {

    constructor(props) {
        super(props)
        this.state = {
			infoList:[
    {
      "addressCode": "地区编码",
      "approContent": "审核不通过原因",
      "area": "区",
      "city": "市",
      "createTime": "创建时间",
      "creator": "创建人",
      "creatorContact": "联系方式",
      "creatorId": "创建人ID",
      "eaIsAppro": "企业审核状态(0待审核，1审核通过，2审核未通过,3不认证)",
      "entAddr": "企业地址",
      "entAtt": "企业性质",
      "entCreditCode": "社会信用代码",
      "entDis": "所在区域",
      "entInfo": "企业简介",
      "entLicense": "营业执照",
      "entLicenseUrl": "营业执照URL",
      "entName": "企业名称",
      "entOrderCount": "企业工单数量",
      "entOwner": "法人姓名",
      "entPhoto": "企业头像",
      "entPhotoUrl": "企业url",
      "entType": "企业类型",
      "fileList": [
        {
          "cfFileId": "string",
          "cfFileName": "string",
          "cfFileUrl": "string",
          "cfType": "string",
          "createTime": "2018-08-08",
          "creator": "测试001",
          "creatorContact": "测试联系方式001",
          "creatorId": "测试001",
          "id": 1000001,
          "refEntId": "测试企业id001",
          "refImId": "测试个人id001",
          "status": "测试001",
          "updateTime": "2018-08-08",
          "updator": "测试001",
          "updatorId": "测试001"
        }
      ],
      "functionalConfiguration": "功能配置0：销售订单审核1:销售配车审核 2 全选",
      "iceMoney": "冻结金额",
      "id": "企业信息主键",
      "ieDimensionality": "企业纬度",
      "ieLongitude": "企业经度",
      "ieType": "信息类型0:门店1:企业",
      "inMoney": "收入总金额",
      "invitationCode": "推荐邀请码",
      "operatingState": "营业状态：0：营业中1：休息中",
      "parentDeptId": "父级架构id",
      "parentId": "父ID",
      "propertyList": [
        {
          "comId": "企业ID",
          "createBy": "创建人",
          "createTime": "创建时间",
          "epId": "企业性质ID主键",
          "epSort": "企业性质0:企业维修商,1.汽车配件商2.汽车经销商",
          "modifyBy": "修改人",
          "modifyTime": "修改时间",
          "recStatus": "逻辑删除",
          "remark": "备注"
        }
      ],
      "province": "省",
      "recStatus": "逻辑删除",
      "refDeptId": "部门id",
      "scope": "业务范围",
      "status": "状态",
      "thisInvitationCode": "自己邀请码",
      "updateTime": "修改时间",
      "updator": "修改人",
      "updatorId": "修改人ID"
    }
  ],
			tabList: [{ title: '支付冻结' }, { title: '收到冻结' }],
			active: 0,
			entName:'',
            title: '车商',
            obj: {
                page: 1,
                limit: 10,
				name:''
            },
            scrollStyle: window.screen.availHeight,
            footerStatus: false,
            list: [],
            totalPage: 1
        }
    }
    componentWillMount() {
        this.getCarsDealer()
    }
	handleClick(value) {
	  let { id } = this.state
	  this.setState({
	    active: value,
	    obj1: {
	      page: 1,
	      limit: 10
	    },
	    list: [],
	    scrollStyle: window.screen.availHeight,
	    footerStatus: false,
	    totalPage: 1
	  }, () => {
	    if (value === 0) {
	      this.getCarsDealer(id, 1)
	    }
	    if (value === 1) {
	      this.getCarsDealer(id, 2)
	    }

	  })
	}
    getCarsDealer(name = '') {
        let { page, limit } = this.state.obj
        let { list, totalPage } = this.state
        let obj = {
            page,
            limit,
			
        }
		this.setState({
		    list: [],
		    totalPage: 1,
			obj,
			entName:name
		})
	
        if (page > totalPage) {
            this.setState({
                footerStatus: true
            })
            return
        }
		let _http,carform = this.props.carform,listt = []
        if(carform){
			_http = http['getEntList']({
			outColor:carform.outColor,
			carModelId:carform.carModelId
			})
			// listt = this.state.infoList
		}else{
			obj.entName = name || this.state.entName
			// listt = this.state.infoList
			_http = http['getCarsDealer'](obj)
		}
		let arr = []
        _http.then(res => {
		
			(carform?res:res.list).map(item=>{
				arr.push({title:item.entName,
				// extraText:item.payPrice,
				arrow:'right',
				id:item.id,
				iconInfo:item.id,
				note:<View ind={item.id}>{item.entAddr}<View></View><View>联系方式:  {item.creator} {item.creatorContact}</View></View>,
				 thumb:entLogo||'https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=1126073469,2920192133&fm=26&gp=0.jpg'//entLicenseUrl
				})
			})
            this.setState({
                list: arr,
                totalPage: res.totalPage || 1
            })
        })
		// listt.map(item=>{
		// 	arr.push({title:item.entName,
		// 	// extraText:item.payPrice,
		// 	arrow:'right',
		// 	note:<View>{item.entName}<View></View><View>联系方式:  {item.creator} {item.creatorContact}</View></View>,
		// 	 thumb:item.entPhotoUrl||'https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=1126073469,2920192133&fm=26&gp=0.jpg'//entLicenseUrl
		// 	})
		// })
		// this.setState({
		//     list: arr,
		//     totalPage: 1
		// })
    }
    onScroll = () => {
        this.setState({
            obj: {
                ...this.state.obj,
                page: this.state.obj.page + 1
            }
        }, () => {
            this.getCarsDealer()
        })
    }
    onClickFn(val,list){
		debugger
		const {carform} = this.props
		Taro.navigateTo({
			url:'/pages/companydetail/companydetail?tab=0&id='+val.id+'&type='+(carform?2:1)
		})
	}
    render() {
		
        const {active,tabList, title, list, scrollStyle, footerStatus } = this.state
		const {carform} = this.props
		console.log('list',list)
        return (
            <View className="b_financingrecord b_carsDealer b_drawback__box">
                {!carform&&<DNavBar title={title}></DNavBar>}
				 {!carform&&<View className='b_drawback__box_search flex-box'>
		  <DAtInpute onChange={this.getCarsDealer.bind(this)} value={this.state.entName}
			placeholder="搜索车商名称"></DAtInpute>
		  <AtButton size="small" onClick={this.getCarsDealer.bind(this,this.state.entName)}  type='secondary' >搜索</AtButton>
		  </View>/* <AtInput
				  clear
				  title={<View className='at-icon at-icon-search' />}
				  type='text'
				  maxLength='4'
				  placeholder='搜索车商名称'
				  value={this.state.entName}
				  }
				/>*/}
				<View className="b_financingrecord__box">
				<ScrollView
				    scrollY
				    scrollWithAnimation
				    lowerThreshold='20'
				    style={`height:${scrollStyle - 50}PX`}
				    onScrollToLower={this.onScroll}>
					{list.length>0&&<AtList>
					
					 { list.map((item, i) => {
					     return <AtListItem index={item} onClick={this.onClickFn.bind(this,item)}  hasBorder={true} key={i} {...item}/>
                       })
					    }
					</AtList>
					}
					
				   {
				      footerStatus && <View className='b_financingrecord__more'>暂无更多</View>
				   }
				   {
				     list.length==0 && <DItemError></DItemError>
				   }
				       </ScrollView>
                   </View>
				   
            </View>
        )
    }
}
